package com.mallcloud.mall.app.api.entity.dto;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;
import com.mallcloud.mall.common.core.exception.FailException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@ApiModel(value = "AppOrderXglPageDTO", description = "星光里账单查询")
@Data
public class AppOrderXglPageDTO implements Serializable {
	private static final long serialVersionUID = 1L;

	@NotBlank(message = "查询日期不能为空")
	@ApiModelProperty("商户手机")
	private String phone;

	@NotNull(message = "查询日期范围不能为空")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	@ApiModelProperty("查询日期范围")
	private List<Date> queryDate;
	public void setQueryDate(List<Date> queryDate) {
		if(queryDate.size() != 2){
			throw new FailException("查询日期范围格式错误");
		}
		this.queryDate = Lists.newArrayList(
				DateUtil.beginOfDay(queryDate.get(0)),
				DateUtil.endOfDay(queryDate.get(1))
		);
	}

	@ApiModelProperty("柜组")
	private String cabinetGroupCode;
}
